﻿using System;
using System.IO;
using System.Text;

namespace HeerCards.Helper
{
    public class ProCodeSaver
    {
        public string Dir { get; set; }
         void checkKeyFile()
        {
            if (!File.Exists(Dir + "code.key"))
            {
                File.Create(Dir + "code.key").Close();
            }
        }
         void checkKeyFile(string dir)
        {
            if (!File.Exists(dir + "code.key"))
            {
                File.Create(dir + "code.key").Close();
            }
        }
        public  string loadCode()
        {
            checkKeyFile();
            var str = File.ReadAllText(Dir + "code.key");
            var o = Convert.FromBase64String(str);
            return Encoding.UTF8.GetString(o);
        }
        public  string loadCode(string dir)
        {
            checkKeyFile(dir);
            var str = File.ReadAllText(dir + "code.key");
            var o = Convert.FromBase64String(str);
            return Encoding.UTF8.GetString(o);
        }
        public  void saveCode(string code)
        {
            checkKeyFile();
            var b = Encoding.UTF8.GetBytes(code);
            var o = Convert.ToBase64String(b);
            File.WriteAllText(Dir + "code.key", o);
        }
    }
}
